# -*- coding: utf-8 -*-

import logging

from odoo import models, fields, api
from odoo.exceptions import UserError, ValidationError

_logger = logging.getLogger(__name__)


class ProductTemplate(models.Model):
    _inherit = 'product.template'

    @api.model
    def default_get(self, fields_list):
        defaults = super(ProductTemplate, self).default_get(fields_list)
        add_val = {}
        if 'is_gongyi' in self.env.context:
            categ_id = self.env.ref('lmch_buliao.product_category_gongyi')
            add_val.update(categ_id=categ_id.id, type='service', purchase_ok=False)
            defaults.pop('taxes_id', [])
            defaults.pop('supplier_taxes_id', [])
        if 'is_haocai' in self.env.context:
            categ_id = self.env.ref('lmch_buliao.product_category_haocai')
            add_val.update(categ_id=categ_id.id, type='product', sale_ok=False)
            defaults.pop('taxes_id', [])
            defaults.pop('supplier_taxes_id', [])
        defaults = dict(defaults, **add_val)
        return defaults
